package edu.gxnu.cetcdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.gxnu.cetcdemo.mapper.MaterialsMapper;
import edu.gxnu.cetcdemo.pojo.Materials;
import edu.gxnu.cetcdemo.service.MaterialsService;
import edu.gxnu.cetcdemo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Uplifted
* @description 针对表【materials】的数据库操作Service实现
* @createDate 2024-04-02 15:09:11
*/
@Service
public class MaterialsServiceImpl extends ServiceImpl<MaterialsMapper, Materials>
    implements MaterialsService{

    @Autowired
    private MaterialsMapper materialsMapper;

    @Override
    public Result queryMaterialsList() {
        Map data = new HashMap();
        List<Materials> materialsList = materialsMapper.selectList(null);
        data.put("materialsList", materialsList);
        return Result.build(200, "成功查询所有物资信息", data);
    }

    @Override
    public Result addMaterials(Materials materials) {
        materialsMapper.insert(materials);
        return Result.build(200, "物资信息添加成功");
    }

    @Override
    public Result updateMaterials(Materials materials) {
        materialsMapper.update(materials, new LambdaQueryWrapper<Materials>().eq(Materials::getMaterialsId,materials.getMaterialsId()));
        return Result.build(200, "物资信息更新成功");
    }

    @Override
    public Result delMaterials(long id) {
        materialsMapper.delete(new LambdaQueryWrapper<Materials>().eq(Materials::getMaterialsId, id));
        return Result.build(200, "物资信息删除成功");
    }
}




